import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    component: () => import('../views/admin/Login.vue')
  },
  {
    path: '/',
    redirect: '/main-m1',
    component: () => import('../views/admin/Index.vue'),
    children: [
      { path: '/main-m1', component: () => import('../views/model1/index.vue') },
      { path: '/main-m2', component: () => import('../views/model2/index.vue') },
    ]
  }
]

// 解决重复点击路由报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}

const router = new VueRouter({
  mode: 'history',
  routes
})


// 全局前置守卫
// 在Router实例上进行守卫
router.beforeEach((to, from, next) => {
  next()
})

export default router
